package com.far.game.xiuzhen.common.utils.game;

import cn.hutool.core.util.ArrayUtil;
import com.far.game.xiuzhen.common.database.entity.Partner;
import com.far.game.xiuzhen.common.database.entity.Vo.PartnerVo;
import com.far.game.xiuzhen.common.enums.game.JobEnums;
import com.far.game.xiuzhen.common.enums.game.PartnerInitData;
import com.far.game.xiuzhen.common.enums.game.RaceEnums;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/*
 * @description: 伙伴基础导入工具类
 * @author mike/Fang.J/Q184377367
 * @date 2022/7/23 22:30
 */


public class ImportPartnerUtil {


    public static Map<Integer, Map<String, Double>> defSettings = new HashMap<>();

    static {
        //战士的物防法防生成规则
        Map<String, Double> zval = new HashMap<>();
        zval.put("pdefr", 0.75);
        zval.put("mdefr", 0.75);
        zval.put("hit", 98D);
        defSettings.put(JobEnums.ZHAN.getVal(), zval);
        //肉盾的
        Map<String, Double> dval = new HashMap<>();
        dval.put("pdefr", 0.52);
        dval.put("mdefr", 0.52);
        dval.put("hit", 95D);
        defSettings.put(JobEnums.DUN.getVal(), dval);

        //辅助的
        Map<String, Double> fval = new HashMap<>();
        fval.put("pdefr", 0.68);
        fval.put("mdefr", 0.68);
        fval.put("hit", 98D);
        defSettings.put(JobEnums.FU.getVal(), fval);

    }

    /**
     * @param partner
     * @description:excel导入的数据转换 根据职业 种族，品质 自动计算 战斗属性
     * @return: com.far.game.xiuzhen.common.database.entity.Partner
     * @author mike/Fang.J/Q184377367
     * @date: 2022/7/23 23:13
     */
    public static Partner calculateBattleAttr(PartnerVo partner) {


        //基础数据
        if ("战".equals(partner.getJob())) {
            return calc(PartnerInitData.zhanData, partner);
        } else if (partner.getJob().equals("盾")) {
            return calc(PartnerInitData.dunData, partner);
        } else if (partner.getJob().equals("辅")) {
            return calc(PartnerInitData.fuData, partner);
        } else if (partner.getJob().equals("医")) {
            partner.setJob("辅");
            return calc(PartnerInitData.fuData, partner);
        }


        return null;

    }

    public static Partner calc(Partner srcPartner, PartnerVo partner) {

        Partner partnerData = new Partner();
        //设置人物介绍
        partnerData.setIntroduce(partner.getIntroduce());
        //设置品阶
        partnerData.setQuality(partner.getQuality());
        //设置人物名称
        partnerData.setPartnerName(partner.getPartnerName());
        //默认都是1区
        partnerData.setDomainId(1);
        //设置职业
        partnerData.setJob(JobEnums.valueOfName(partner.getJob()));

        //设置种族
        partnerData.setRace(RaceEnums.valueOfName(partner.getRace()));
        //设置能量
        partnerData.setPower(1000);
        //设置最大能量
        partnerData.setMaxPower(1000);
        //设置修为
        partnerData.setExp(1L);
        //设置等级
        partnerData.setLev(1);
        //设置飞升
        partnerData.setFly(1);
        //设置轮回
        partnerData.setLifeBack(1);
        //设置升星
        partnerData.setStar(1);
        //根据攻击计算各项属性
        //设置攻击力
        partnerData.setAttack(calcQl(srcPartner.getAttack(), partner.getQuality()));
        //血量
        partnerData.setBlood(calcBlood(srcPartner.getAttack(), 2.8, partner.getQuality()));
        //最大血量
        partnerData.setMaxBlood(partnerData.getBlood());
        //物防
        partnerData.setPdef(
                calcPdef(srcPartner.getAttack(), defSettings.get(partnerData.getJob()).get("pdefr"), partner.getQuality())
        );
        partnerData.setMdef(
                calcMdef(srcPartner.getAttack(), defSettings.get(partnerData.getJob()).get("mdefr"), partner.getQuality())
        );

        //命中设置
        partnerData.setHit(defSettings.get(partnerData.getJob()).get("hit"));
        partnerData.setDodge(1d);
        partnerData.setCrit(1d);
        partnerData.setRevolt(1d);
        return partnerData;
    }


    public static long calcBlood(long attack, double number, int ql) {
        long val = new Double(Math.ceil(attack + attack * number)).longValue();
        return calcQl(val, ql);
    }

    /**
     * @param attack
     * @param number
     * @param ql
     * @description:物防设置
     * @return: long
     * @author mike/Fang.J/Q184377367
     * @date: 2022/7/27 22:38
     */
    public static long calcPdef(long attack, double number, int ql) {
        long val = new Double(Math.ceil(attack - attack * number)).longValue();
        return calcQl(val, ql);
    }

    /**
     * @param attack
     * @param number
     * @param ql
     * @description:法防
     * @return: long
     * @author mike/Fang.J/Q184377367
     * @date: 2022/7/29 16:28
     */
    public static long calcMdef(long attack, double number, int ql) {
        long val = new Double(Math.ceil(attack - attack * number)).longValue();
        return calcQl(val, ql);
    }


    /**
     * @param val
     * @description:品质换算结果
     * @return: long
     * @author mike/Fang.J/Q184377367
     * @date: 2022/7/27 22:31
     */
    public static long calcQl(long val, int ql) {

        double qualityVal[] = {
                0,
                1,
                1.2,
                1.5,
                2.5,
                3
        };
        double nVal = val * qualityVal[ql];
        return new Double(nVal).longValue();

    }


    public static void main(String[] args) {
        PartnerVo partnerVo = new PartnerVo();
        partnerVo.setJob("战");
        partnerVo.setRace("人");
        partnerVo.setQuality(1);
        ImportPartnerUtil.calculateBattleAttr(partnerVo);
    }


}
